package models;
import android.text.format.Time;

/**
 * 
 * Represents a single task in a schedule. No task can have a negative duration, travel time, or priority.
 * In addition, durations can be 0 for "instantaneous" events.
 * 
 * @author Ajay Menon, Richard Pan
 *
 */
public class Task {
	private final long taskId;
	private String title;
	private Time startTime;
    private int estimatedDuration;
    private int estimatedTravel;
    private int priority;
    private boolean completed;
    
	/**
     * Constructor that creates a Task object with a specified start time.

	 * @param title
	 * @param startTime
	 * @param estimatedDuration
	 * @param estimatedTravel
	 * @param priority
	 * @param completed
	 */
	public Task(long taskId,String title, Time startTime, int estimatedDuration, int estimatedTravel, int priority, boolean completed) {
		if(title == null || title == "" || estimatedDuration <= 0 || estimatedTravel < 0 || priority < 0) {
			throw new IllegalArgumentException();
		}
		this.taskId = taskId;
		this.title = title;
		this.startTime = startTime;
		this.estimatedDuration = estimatedDuration;
		this.estimatedTravel = estimatedTravel;
		this.priority = priority;
		this.completed = completed;
	}

	/**
	 * Sets the title for the task
	 * @param title Title for the task
	 * @exception IllegalArgumentException If the passed title is empty or null
	 */
	public void setTitle(String title) {
		if (title == null || title.equals("")) {
			throw new IllegalArgumentException("Invalid task name.");
		}
		this.title = title;
	}
	
	/**
	 * Sets start time for the user.
	 * @param startTime Time of the day that the task begins at.
	 * 
	 */
	public void setStartTime(Time startTime) {
		this.startTime = startTime;
	}
	
	/**
	 * Sets estimatedDuration for the user
	 * @param estimatedDuration Amount of time that a task will take.
	 * @exception IllegalArgumentException If estimatedDuration is negative.
	 */
	public void setEstimatedDuration(int estimatedDuration) {
		if (estimatedDuration <= 0) {
			throw new IllegalArgumentException("Cannot have a negative estimatedDuration.");
		}
		this.estimatedDuration = estimatedDuration;
	}
	
	/**
	 * Sets travel time for the user
	 * @param estimatedTravel Amount of time it takes to travel to a destination
	 * @exception IllegalArgumentException If travel time is negative
	 */
	public void setEstimatedTravel(int estimatedTravel) {
		if (estimatedTravel < 0) {
			throw new IllegalArgumentException("Cannot have a negative travel time.");
		}
		this.estimatedTravel = estimatedTravel;
	}
	
	/** Sets priority of the task
	 *  @param priority Positive integer representation of the task priority
	 *  @exception IllegalArgumentException If priority is negative
	 */
	public void setPriority(int priority) {
		if (priority < 0) {
			throw new IllegalArgumentException("Cannot have a negative priority.");
		}
		this.priority = priority;
	}
	
	/**
	 * Sets the completion status of this Task.
	 * @param completed - if the task has been completed
	 */
    public void setCompleted(boolean completed) {
        this.completed = completed;
    }
    
    /**
     * Gets the object's id 
     * @return unique taskID for this object
     */
    public long getID() {
        return this.taskId;
    }
    
    /**
     * Gets the object's title 
     * @return Task title
	 */
	 public String getTitle() {
    	return this.title;
    }
 
    
    /**
     * Gets the object start time
     * @return object start time
     */
    public Time getStartTime() {
    	return startTime;
    }
    
    /**
     * Retrieves the estimated estimatedDuration of the task
     * @return Estimated estimatedDuration of the task
     */
    public int getEstimatedDuration() {
    	return this.estimatedDuration;
    }
    
    /**
     * Whether the task has been completed or not
     * @return True if the task has been completed; false if not 
     */
    public boolean isCompleted() {
        return this.completed;
    }
    
    public int getEstimatedTravel() {
    	return estimatedTravel;
    }
    
    /**
     * Gets the priority of the task
     * @return int priority
     */
    public int getPriority() {
    	return this.priority;
    }
    
    /**
     * Determines the equality of tasks. Equality is determined via taskId matching.
     * @return True if the objects are equal; False otherwise.
     */
    @Override 
    public boolean equals(Object other)
    {
    	if (other == null) {
    		return false;
    	}
        if (other instanceof Task) {
            Task that = (Task) other;
            return (this.taskId == that.taskId);
        }
        return false;
    }
    
    /**
     * Returns the hashCode for this task. Hashcodes are set via taskIds.
     */
    @Override 
    public int hashCode() {
        return (int)taskId;
    }
}
